<?php // no direct access
defined('_JEXEC') or die('Restricted access');
JHTML::_('behavior.tooltip');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.path');
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
JHTML::stylesheet('base.css', JURI::root().'/components/com_simplelisting/css/');

?>

<script language="javascript" type="text/javascript">

</script>
<table width="100%">
    <tr>
        <td width="60%" valign="top"><!-- begin left side field options -->
        <form action="" method="POST" name="adminForm" id="adminForm" enctype="multipart/form-data">
           <fieldset class="adminform">
                 <legend><?php echo JText::_('HEADER_LISTING_DETAILS') ?></legend>
                 <table class="admintable">
                        <tr>
                            <td class="key"><label for="name"><?php echo JText::_('LABEL_NAME') ?></label></td>
                            <td><input type="text" name="name" id="name" size="50" maxlength="100" value="<?php echo $this->simplelisting->name; ?>" /></td>
                        </tr>
                        <tr>
                            <td class="key" valign="center">
                                <label for="description">
                                    <?php echo JText::_('LABEL_DESCRIPTION') ?>
                                </label>
                            </td>
                            <td>
                                                <?php
                    $editor =& JFactory::getEditor();
                    echo $editor->display('description', $this->simplelisting->description, '100%', '100%', '70', '40', array('pagebreak', 'readmore', 'image') );
                    ?>
                            </td>
                        </tr>
                        <tr>
                            <td class="key" valign="center">
                                <label for="address1">
                                <?php echo JText::_('LABEL_ADDRESS') ?>
                                </label>
                            </td>
                        <td>
                            <textarea class="text_area" name="address" id="address" ><?php echo $this->simplelisting->address; ?></textarea>
                        </td>
                        </tr>
                        <tr>
                            <td class="key" nowrap>
                                <label for="countries_id">
                                <?php echo JText::_('LABEL_COUNTRY') ?>
                                </label>
                            </td>
                            <td ><?php
                                $db =& JFactory::getDBO();
                                $query = 'SELECT a.* FROM #__simplelisting_countries as a ORDER BY a.ordering ASC';

                                $db->setQuery( $query );
                                $countrylist[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_COUNTRY' ), 'id', 'name' );
                                $countrylist = array_merge( $countrylist, $db->loadObjectList() );
                                $lists['id']   = JHTML::_('select.genericlist', $countrylist, 'countries_id', 'class="inputbox" size="1"','id', 'name', $this->simplelisting->countries_id );
                                echo $lists['id'];
                            ?></td>
                        </tr>
                         <tr>
                            <td class="key" nowrap>
                                <label for="category_id">
                                <?php echo JText::_('LABEL_CATEGORY') ?>
                                </label>
                            </td>
                            <td><?php
                                $db =& JFactory::getDBO();
                                $category_id='category_id';
                                $query = 'SELECT a.* FROM #__simplelisting_categories as a ORDER BY a.ordering ASC';
                                $db->setQuery( $query );
                                $categorylist[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_CATEGORY' ), 'id', 'name' );
                                $categorylist = array_merge( $categorylist, $db->loadObjectList() );
                                $lists['id']   = JHTML::_('select.genericlist', $categorylist, 'category_id', 'class="inputbox" size="1"','id', 'name', $this->simplelisting->category_id );
                                echo $lists['id'];
                            ?></td>
                        </tr>
                        <tr>
                            <td class="key" nowrap>
                                <label for="type_id">
                                <?php echo JText::_('LABEL_TYPE') ?>
                                </label>
                            </td>
                            <td ><?php
                                $db =& JFactory::getDBO();
                                 $query = 'SELECT a.* FROM #__simplelisting_types as a ORDER BY a.ordering ASC';
                                $db->setQuery( $query );
                                $typelist[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_TYPE' ), 'id', 'name' );
                                $typelist = array_merge( $typelist, $db->loadObjectList() );
                                $lists['id']   = JHTML::_('select.genericlist', $typelist, 'type_id', 'class="inputbox" size="1"','id', 'name', $this->simplelisting->type_id );
                                echo $lists['id'];

                            ?></td>
                        </tr>
                        <tr>
                            <td class="key" nowrap>
                                <label for="extra_id">
                                <?php echo JText::_('LABEL_EXTRAS') ?>
                                </label>
                            </td>
                            <td><?php
                                $db =& JFactory::getDBO();
                                $extra_id='extra_id';
                                $query = 'SELECT a.* FROM #__simplelisting_extras as a ORDER BY a.ordering ASC';
                                $db->setQuery( $query );
                                $extralist[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_EXTRAS' ), 'id', 'name' );
                                $extralist = array_merge( $extralist, $db->loadObjectList() );
                                $lists['id']   = JHTML::_('select.genericlist', $extralist, 'extra_id', 'class="inputbox" size="1"','id', 'name', $this->simplelisting->extra_id );
                                echo $lists['id'];
                            ?></td>
                        </tr>
                        <tr>
                            <td class="key" nowrap>
                                <label for="layout_id">
                                <?php echo JText::_('LABEL_LAYOUT') ?>
                                </label>
                            </td>
                            <td><?php
                                $db =& JFactory::getDBO();
                                $layout_id='layout_id';
                                $query = 'SELECT a.* FROM #__simplelisting_layouts as a ORDER BY a.ordering ASC';
                                $db->setQuery( $query );
                                $layoutlist[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_LAYOUT' ), 'id', 'name' );
                                $layoutlist = array_merge( $layoutlist, $db->loadObjectList() );
                                $lists['id']   = JHTML::_('select.genericlist', $layoutlist, 'layout_id', 'class="inputbox" size="1"','id', 'name', $this->simplelisting->layout_id );
                                echo $lists['id'];
                            ?></td>
                        </tr>
                        <tr>
                            <td class="key">
                                <label for="price">
                                <?php echo JText::_('LABEL_PRICE') ?>
                                </label>
                            </td>
                            <td>
                                <input type="text" name="price" id="price" size="20" maxlength="50" value="<?php echo $this->simplelisting->price; ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td class="key" valign="center">
                                <label for="facilities">
                                <?php echo JText::_('LABEL_FACILITIES') ?>
                                </label>
                            </td>
                            <td id="items" colspan="2">
                                <table>
                                    <?php
                                    $db =& JFactory::getDBO();
                                    $query = 'SELECT a.* FROM #__simplelisting_facilities as a ORDER BY a.ordering ASC';
                                    $db->setQuery( $query );
                                    $r = $db->loadObjectList();

                                        $facilities = array();
                                        if ( !empty($this->simplelisting->facilities) ) {
                                            $facilities = explode( ',' ,  $this->simplelisting->facilities );
                                        }
                                        $count = 1;
                                        $column = 1;
                                        foreach($r as $k=> $row)
                                        {
                                            $checked = '';
                                            if ( in_array($row->id, $facilities) ) {
                                                $checked = 'checked="checked"' ;
                                            }
                                            $id    = $row->id;
                                            $value = $row->name;
                                            $html = '<input type="checkbox" name="facilities['.$k.']" value="'.$id.'"' .$checked .' />'.$value;
                                            if ($column == 1)
                                            {
                                                printf("<tr><td id='items' nowrap>%s</td>",$html);
                                            }else if ($column == 2){
                                                printf("<td id='items' nowrap>%s</td>",$html);
                                            }else if ($column == 3){
                                                printf("<td id='items' nowrap>%s</td>",$html);
                                            }else{
                                                printf("<td id='items' nowrap>%s</td></tr>",$html);
                                            }

                                            $count += 1;

                                            $column = $count % 4;
                                        }
                                    ?>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td width="20%" class="key">
                                <label for="published">
                                    <?php echo JText::_('LABEL_PUBLISHED')?>
                                </label>
                            </td>
                            <td id="items">
                                    <?php echo JHTML::_('select.booleanlist',  'published', '', $this->simplelisting->published ); ?>
                            </td>
                        </tr>
                            <!-- Hidden fields outside the table structure -->
                            <?php
                            $user =& JFactory::getUser();
                            if(empty($this->simplelisting->id)):
                            ?>
                            <input type="hidden" name="create_by" value="<?php echo $user->id; ?>"/>
                            <input type="hidden" name="date_created" value="<?php echo date('Y-m-d H:i:s') ?>"/>
                            <?php
                            else:
                            ?>
                            <input type="hidden" name="modify_by" value="<?php echo $user->id; ?>"/>
                            <input type="hidden" name="date_modified" value="<?php echo date('Y-m-d H:i:s') ?>"/>
                            <?php endif; ?>
                            <!--End hidden Fields -->
                        <tr>
                            <td class="key">
                                <label for="date_created">
                            <?php echo JText::_( 'LABEL_POSTED_DATE' )?>
                                </label>
                            </td>
                            <td id="items">
                            <?php echo JHTML::_('date',  $this->simplelisting->date_created,  JText::_('DATE_FORMAT_LC2') ) ?>
                            </td>
                        </tr>
                 </table>
             </fieldset>
               <input type="hidden" name="option" value="<?php echo JRequest::getVar( 'option' );?>"/>
               <input type="hidden" name="view" value="listings" />
               <input type="hidden" name="id" value="<?php echo $this->simplelisting->id; ?>"/>
               <input type="hidden" name="task" value=""/>
               <?php echo JHTML::_('form.token'); ?>
        </form>
    </td><!-- End left side field options -->

    <td valign="top"  height="100%"><!--Start of right side form -->
        <?php if(!empty($this->simplelisting->id)):?>
        <fieldset class="adminform"><!-- Start contact details -->
             <legend><?php echo JText::_('HEADER_AUTHOR_DETAILS')?></legend>
                <table class="admintable">
                   <tr>
                       <td class="key">
                         <?php echo JText::_('LABEL_CONTACT_NAME') ?>
                       </td>
                       <td id="items">
                         <?php echo $this->escape( $this->simplelisting->username); ?>
                       </td>
                   </tr>
                   <tr>
                       <td class="key">
                         <?php echo JText::_('LABEL_CONTACT_TELEPHONE') ?>
                       </td>
                       <td id="items">
                         <?php echo $this->escape( $this->simplelisting->tel); ?>
                       </td>
                   </tr>
                   <tr>
                       <td class="key">
                         <?php echo JText::_('LABEL_CONTACT_MOBILE') ?>
                       </td>
                       <td id="items">
                         <?php echo $this->escape( $this->simplelisting->mobile); ?>
                       </td>
                   </tr>
                   <tr>
                       <td class="key">
                         <?php echo JText::_('LABEL_CONTACT_FAX') ?>
                       </td>
                       <td id="items">
                         <?php echo $this->escape( $this->simplelisting->fax); ?>
                       </td>
                   </tr>
                   <tr>
                       <td class="key">
                         <?php echo JText::_('LABEL_CONTACT_EMAIL') ?>
                       </td><td id="items">
                         <?php echo $this->escape( $this->simplelisting->email); ?>
                       </td>
                   </tr>
                  <tr>
                       <td class="key">
                         <?php echo JText::_('LABEL_CONTACT_COUNTRY') ?>
                       </td><td id="items">
                         <?php echo $this->escape( $this->simplelisting->usercountry); ?>
                       </td>
                   </tr>
                   <tr>
                       <td class="key">
                         <?php echo JText::_('LABEL_CONTACT_MISC') ?>
                       </td><td id="items">
                         <?php echo $this->escape( $this->simplelisting->misc); ?>
                       </td>
                   </tr>
               </table>
   </fieldset><!-- End contact details -->

   <form action="" method="post" enctype="multipart/form-data">
        <fieldset class="adminform"><!--Start main image upload -->
            <legend><?php echo JText::_('HEADER_MAIN_IMG') ?></legend>
                <table class="admintable" >
                    <tr>
                        <td height="120px"  valign="top">
                            <input type="file" name="upload_file" size="" />
                            <input type="submit" name="submit" value="<?php echo JText::_('BT_UPLOAD') ?>" class="button" /><br />
                            <?php
                            $main = JPATH_ROOT.'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id;
                            if ( !JFolder::exists($main) ) { JFolder::create($main); }

                            if ( is_file( $main.'/main.jpg') ) : ?>
                            <fieldset style="margin-top:10px; width:130px">
                                <a href="<?php echo JURI::root().'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/main.jpg' ?>" >
                                <img src="<?php echo JURI::root().'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/main.jpg' ?>" border="0" alt="No Image" width="100" />
                                </a>
                                <a href="<?php echo JRoute::_('index.php?option=com_simplelisting&controller=listings&task=delete_main&id='.$this->simplelisting->id) ; ?>">
                                <?php echo JHTML::_('image.site', 'delete.png', '../components/com_simplelisting/images/') ?>
                                </a>
                            </fieldset>
                            <?php endif;?>
                        </td>
                    </tr>
                </table>
                <input type="hidden" name="task" value="upload_main" />
                <input type="hidden" name="view" value="listings" />
                <input type="hidden" name="option" value="<?php echo JRequest::getVar( 'option' );?>"/>
                <input type="hidden" name="id" value="<?php echo $this->simplelisting->id; ?>"/>
                <?php echo JHTML::_('form.token'); ?>
        </fieldset>
    </form><!-- End main image upload -->

    <form action="" method="post" enctype="multipart/form-data"><!-- Start Galley upload form -->
        <fieldset class="adminform">
            <legend><?php echo JText::_('HEADER_GALLERY_IMG') ?></legend>
                <table class="admintable">
                    <tr>
                        <td>
                            <input type="file" id="upload_file[]" name="upload_file[]">
                            <input type="submit" name="submit" value="<?php echo JText::_('BT_UPLOAD') ?>" class="button" /><br />
                            <div style="height:222px; width:150px;overflow:auto;">
                                <?php
                                $base_upload_dir = '../components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/second/';
                                 if ( JFolder::exists($base_upload_dir)){

                                        $image = JFolder::files( $base_upload_dir );

                                        for($i=0;$i<count($image);$i++) {
                                             $im = $base_upload_dir.DS.$image[$i];
                                        ?>
                                        <fieldset style="margin-top:10px;">
                                        <img src="<?php echo $im; ?>" border="0" alt="Image" width="100" />&nbsp;
                                        <a href="<?php echo JRoute::_('index.php?option=com_simplelisting&controller=listings&task=delete_sec&id='.$this->simplelisting->id.'&image='.$image[$i]) ; ?>">
                                        <img src="../components/com_simplelisting/images/delete.png" alt="_IMAGEBROWSER_DELETE;" border="0" /></a>
                                        </a>
                                        </fieldset>
                                        <?
                                        }
                                }

                                ?>
                            </div>
                        </td>
                    </tr>
                </table>
                <input type="hidden" name="task" value="upload_second" />
                <input type="hidden" name="view" value="listings" />
                <input type="hidden" name="option" value="<?php echo JRequest::getVar( 'option' );?>"/>
                <input type="hidden" name="id" value="<?php echo $this->simplelisting->id; ?>"/>
                <?php echo JHTML::_('form.token'); ?>
       </fieldset>
    </form><!-- End gallery upload form -->
    <?php endif; ?>
        </td><!--End right side form-->
    </tr>
</table>


